from celery import shared_task
from tools.myredis import r
from tools.bdapi import baidu
import json

@shared_task
def bdcardmes():
    # 从redis list中获取10条信息
    # 调用百度api接口
    # 将结果存入redis
    blist = r.list_lrange('idcardlist', 0, 10)
    if blist:
        for i in blist:
            picurl = i.decode('utf-8')
            print(picurl)
            mes = baidu.idcard(picurl)
            print(mes)
            # 存入redis
            r.set_str(picurl, json.dumps(mes))
            r.list_del('idcardlist', picurl)

    print("调用百度api接口")